package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级相关接口")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    //查询所有护理等级
    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级",notes = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> getlistAll(){

         List<NursingLevelVo> nursingLevelVo = nursingLevelService.getlistAll();
        return ResponseResult.success(nursingLevelVo);
    }


    //新增
    @PostMapping("insert")
    @ApiOperation(value = "护理等级新增",notes = "护理等级新增")
    public ResponseResult createInsert(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.createInsert(nursingLevelDto);
        return ResponseResult.success();
    }



    //条件分页查询
    @GetMapping("/listByPage")
    @ApiOperation(value = "护理等级分页查询",notes = "护理等级分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>>getListByPage( @ApiParam(value ="护理等级名称") String name,
                                                                      @ApiParam(value = "护理等级状态")Integer status,
                                                                      @ApiParam(value = "当前状态")
                                                                          @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
                                                                      @ApiParam(value = "每页显示的大小")
                                                                          @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
        PageResponse<NursingLevelVo> pageResponse=nursingLevelService.getListByPage(pageNum,pageSize,name,status);
        return ResponseResult.success(pageResponse);
    }

    //根据id查询
    @GetMapping("/{id}")
    @ApiOperation(value = "护理等级根据id查询",notes = "护理等级分页查询")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Integer id){
        NursingLevelVo  nursingLevelVo= nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);

    }

    //修改
    @PutMapping("/update")
    @ApiOperation(value = "护理等级修改",notes = "护理等级修改")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }

    //删除
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "护理等级删除",notes = "护理等级删除")
    public ResponseResult deleteId(@PathVariable Integer id){
        nursingLevelService.deleteId(id);
        return ResponseResult.success();
    }
    //启用禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "护理等级启用禁用",notes = "护理等级启用禁用")
    public ResponseResult  Enable(@PathVariable Integer id ,@PathVariable Integer status){
        nursingLevelService.Enable(id,status);
        return ResponseResult.success();
    }

}
